package silentDonkey.web.servlet;

import silentDonkey.service.UserService;
import silentDonkey.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

@WebServlet("/deleteSelectedServlet")
public class DeleteSelectedServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置请求编码
        request.setCharacterEncoding("utf-8");
        // 1.获取所有id
        String[] ids = request.getParameterValues("uid");
        System.out.println(Arrays.toString(ids));
        // 2.调用Service
        UserService service = new UserServiceImpl();
        service.deleteSelectedUser(ids);
        // 3.跳转至查询集合页面
        response.sendRedirect(request.getContextPath() + "/listUserServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
